


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="../../static/js/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/css/view.css"/>
    <title></title>
    <style>
        #test10 {
            margin-left: 100px;
        }
        .imgCss {
            margin-left: 20px;
            height: 200px;
            cursor: pointer;
        }

    </style>
</head>
<body class="">
<form class="layui-form layui-card-body" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名/账号：</label>
        <div class="layui-input-inline">
            <input name="name" class="layui-input" type="text" placeholder="请输入姓名或账号" autocomplete="off" lay-verify="name">
        </div>
        <div class="layui-form-mid layui-word-aux"></div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密码：</label>
        <div class="layui-input-inline">
            <input name="password" class="layui-input" type="password" placeholder="请输入密码" autocomplete="off" lay-verify="pass">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色：</label>
        <div class="layui-input-block">
            <select name="card" id="card" lay-filter="card" >
                <option value=""></option>
                <option value="1">管理员</option>
                <option value="2">普通用户</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">理由：</label>
        <div class="layui-input-block">
            <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <br>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <a class="layui-btn layui-btn-blue" lay-submit lay-filter="addUser">立即添加</a>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="../../static/js/jquery-3.3.1.min.js"></script>
<script src="../../static/js/layui/layui.all.js"></script>

<script>
    //添加user用户
    layui.use('form', function () {
        var form = layui.form;
        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length < 1) {
                    return '账号或姓名太短';
                }
            },
            pass:function (value) {
                if(value.length<5){
                    return '密码至少大于六位';
                }
            },
        });


        //监听提交
        form.on('submit(addUser)', function (data) {

            $card = $("#card").val();

            if ($card == "") {
                layer.msg("未选择角色");
                return false;
            }
            var data = data.field;
            console.log(data);

            $.ajax({
                type: 'post',
                cache: 'false',
                url: '../controller/add_user.php',
                data: {
                    "data": data,
                },
                dataType: 'json',
                success: function (res) {
                    layer.msg(res.msg);
                    return false;
                },
                error: function (dat) {
                    layer.msg("添加失败");
                    return false;
                }


            });

            return false;


        });
    });


</script>
</body>
</html>